<template>
	<view class="homeLayout pageBg">

		<custom-nav-bar title="首页"></custom-nav-bar>

		<!-- 轮播图 -->
		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay
				circular>
				<swiper-item v-for="item in bannerList" :key="item.id">
					<image :src="item.images" mode="aspectFill" />
				</swiper-item>
			</swiper>
		</view>

		<!-- 公告 -->
		<view class="notice">

			<view class="left">
				<uni-icons type="sound-filled" size="20" color="#28b389"></uni-icons>
				<text class="text">公告</text>
			</view>

			<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<swiper-item v-for="item in notice" :key="item.id">{{item.title}}</swiper-item>
				</swiper>
			</view>

			<view class="right">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>

		</view>

		<!-- 推荐 -->
		<view class="select">

			<common-title>
				<template #name>每日推荐</template>

				<template #custom>
					<view class="date">
						<uni-icons type="calendar" color="#28b389" size="18"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
						</view>
					</view>
				</template>
			</common-title>

			<view class="content">
				<scroll-view scroll-x="true">
					<view class="box" v-for="item in randomList" :key="item.id" @click="goPreview(item.id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>

		</view>

		<!-- 头像 -->
		<view class="avatar-section">
			<!-- 标题 -->
			<common-title>
				<template #name>头像精选</template>
				<template #custom>
					<view url="" class="more">共 {{total}}</view>
				</template>
			</common-title>


			<view class="avatar-grid">
				<!-- 前5个：头像图片 -->
				<view class="avatar-item" v-for="i in avatrData" :key="i.id">
					<image :src="i.avatar" class="avatar-img" />
				</view>

				<!-- 第6个：查看更多按钮 -->
				<navigator url="/pagesMember/avatarList/avatarList" class="avatar-item avatar-more">
					<text class="more-text">查看更多</text>
				</navigator>
			</view>
		</view>

		<!-- 列表 -->
		<view class="theme">
			<common-title>
				<template #name>专题精选</template>
				<template #custom>
					<navigator url="" class="more">更多</navigator>
				</template>
			</common-title>

			<view class="content">
				<theme-item v-for="item in classifyList" :key="item.id" :item="item"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>

		</view>

	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'

	import {
		onShareAppMessage,
		onShareTimeline
	} from "@dcloudio/uni-app"

	import {
		apiGetBanner,
		apiGetRandom,
		apiGetNotice,
		apiGetClassify,
		apiAvatar
	} from "@/api/apis.js"

	import {
		fixMinioUrl
	} from "@/utils/img-url.js"


	// =============轮播图=============
	const bannerList = ref([])
	const params = {
		pageNum: 1,
		pageSize: 3
	}
	const getBanner = async () => {
		const res = await apiGetBanner(params)
		bannerList.value = res.data?.list
	}

	//============ 每日推荐 ============
	const randomList = ref([])
	const getDayRandom = async () => {

		const res = await apiGetRandom()
		randomList.value = res.data
	}

	// =============系统公告==========
	const notice = ref([])
	const getNotice = async () => {

		const params = {
			pageNum: 1,
			pageSize: 3
		}
		const res = await apiGetNotice(params)
		notice.value = res.data.list

	}


	// ===========专题精选===========
	const classifyList = ref([])
	const getClassify = async () => {
		const params = {
			pageNum: 1,
			pageSize: 11
		}
		const res = await apiGetClassify(params);
		classifyList.value = res.data?.list
	}

	const goPreview = (id) => {
		uni.navigateTo({
			url: `/pages/preview/preview?id=${id}` // 修改为查询参数格式
		})
	}

	//分享给好友
	onShareAppMessage((e) => {
		return {
			title: "优美图库壁纸",
			path: "/pages/index/index"
		}
	})

	const avatrData = ref([])
	const total = ref(null)
	const loadAvatar = async () => {
		const params = {
			pageNum: 1,
			pageSize: 5
		}
		const res = await apiAvatar(params)
		avatrData.value = res.data?.list
		total.value = res.data.total
	}

	getBanner()
	getDayRandom()
	getNotice()
	getClassify()
	loadAvatar()
</script>

<style lang="scss" scoped>
	.homeLayout {
		.banner {
			width: 750rpx;
			padding: 30rpx 0;

			swiper {
				width: 750rpx;
				height: 450rpx;

				&-item {
					width: 100%;
					height: 100%;
					padding: 0 30rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 16rpx; // 更圆润
						object-fit: cover;
						box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.08); // 轻微阴影
					}
				}
			}
		}

		.notice {
			width: 690rpx;
			height: 80rpx;
			background: #f0fdfa; // 浅绿色背景，更清新
			margin: 20rpx auto; // 上下留白更协调
			border-radius: 80rpx;
			display: flex;
			line-height: 80rpx;
			box-shadow: 0 4rpx 16rpx rgba(40, 179, 137, 0.12); // 绿色主题阴影
			border: 1rpx solid #d1f0e6;

			.left {
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.text {
					color: $brand-theme-color;
					font-weight: bold;
					font-size: 28rpx;
				}
			}

			.center {
				flex: 1;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}

			.right {
				width: 70rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.select {
			padding-top: 50rpx;

			.content {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap;

					.box {
						width: 200rpx;
						height: 430rpx;
						display: inline-block;
						margin-right: 15rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

					.box:last-child {
						margin-right: 30rpx;
					}
				}
			}

			.date {
				color: $brand-theme-color;
				display: flex;
				align-items: center;

				.text {
					margin-left: 5rpx;
				}
			}
		}

		.theme {
			padding: 50rpx 0;

			.more {
				font-size: 30rpx;
				color: #888;
			}

			.content {
				margin-top: 30rpx;
				padding: 0 30rpx;
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3, 1fr);
			}
		}

		/* 头像精选整体容器 */
		.avatar-section {
			margin: 40rpx 0;
			position: relative;

			// 添加背景装饰
			&::before {
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background: linear-gradient(135deg, rgba(255, 255, 255, 0.6) 0%, rgba(240, 253, 250, 0.3) 50%, rgba(255, 255, 255, 0.6) 100%);
				border-radius: 30rpx;
				z-index: 0;
			}
		}

		/* 更多链接（标题右侧） */
		.more {
			font-size: 28rpx;
			color: #666;
			font-weight: 500;
			background: linear-gradient(135deg, rgba(40, 179, 137, 0.1) 0%, rgba(40, 179, 137, 0.05) 100%);
			padding: 12rpx 24rpx;
			border-radius: 20rpx;
			border: 1rpx solid rgba(40, 179, 137, 0.2);
			transition: all 0.3s ease;

			&:hover {
				background: linear-gradient(135deg, rgba(40, 179, 137, 0.15) 0%, rgba(40, 179, 137, 0.1) 100%);
				transform: translateY(-2rpx);
				box-shadow: 0 4rpx 12rpx rgba(40, 179, 137, 0.2);
			}
		}

		/* 网格布局：每行3个 */
		.avatar-grid {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			gap: 20rpx;
			margin: 30rpx 25rpx;
			position: relative;
			z-index: 1;
		}

		/* 每个头像项 */
		.avatar-item {
			width: 200rpx;
			height: 200rpx;
			border-radius: 24rpx;
			overflow: hidden;
			box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.12);
			position: relative;
			transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
			cursor: pointer;

			// 添加内部光效
			&::before {
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%, rgba(0, 0, 0, 0.05) 100%);
				z-index: 1;
				opacity: 0;
				transition: opacity 0.3s ease;
			}

			&:hover {
				transform: translateY(-12rpx) scale(1.05);
				box-shadow: 0 24rpx 56rpx rgba(0, 0, 0, 0.18);

				&::before {
					opacity: 1;
				}

				.avatar-img {
					transform: scale(1.1);
				}
			}

			&:active {
				transform: translateY(-8rpx) scale(1.02);
				transition: all 0.1s ease;
			}
		}

		/* 图片样式 */
		.avatar-img {
			width: 100%;
			height: 100%;
			object-fit: cover;
			transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
			position: relative;
			z-index: 0;
		}

		/* "查看更多"按钮样式 */
		.avatar-more {
			background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
			box-shadow: 0 16rpx 40rpx rgba(102, 126, 234, 0.4);
			position: relative;
			overflow: hidden;
			cursor: pointer;

			// 添加光效动画
			&::before {
				content: '';
				position: absolute;
				top: -50%;
				left: -50%;
				width: 200%;
				height: 200%;
				background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
				animation: shimmer 2.5s infinite;
				z-index: 1;
			}

			// 添加内部装饰
			&::after {
				content: '';
				position: absolute;
				top: 8rpx;
				left: 8rpx;
				right: 8rpx;
				bottom: 8rpx;
				border: 2rpx solid rgba(255, 255, 255, 0.2);
				border-radius: 16rpx;
				z-index: 1;
			}

			&:hover {
				transform: translateY(-8rpx) scale(1.05);
				box-shadow: 0 24rpx 56rpx rgba(102, 126, 234, 0.5);

				&::before {
					animation-duration: 1.5s;
				}
			}

			&:active {
				transform: translateY(-4rpx) scale(1.02);
				transition: all 0.1s ease;
			}
		}

		/* "查看更多"文字 */
		.more-text {
			font-size: 30rpx;
			color: #fff;
			font-weight: 600;
			position: relative;
			z-index: 2;
			text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3);
			letter-spacing: 1rpx;
		}

		/* 点击反馈 */
		.avatar-item:active {
			opacity: 0.9;
			transform: scale(0.98);
		}

		// 添加光效动画
		@keyframes shimmer {
			0% {
				transform: translateX(-100%) translateY(-100%) rotate(45deg);
			}

			100% {
				transform: translateX(100%) translateY(100%) rotate(45deg);
			}
		}
	}
</style>